package edu.gxnu.cetcdemo.controller;

import edu.gxnu.cetcdemo.pojo.Admin;
import edu.gxnu.cetcdemo.service.AdminService;
import edu.gxnu.cetcdemo.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@CrossOrigin
public class AdminController {
    @Autowired
    private AdminService adminService;

    @ApiOperation("机房管理员登录接口")
    @PostMapping("/login")
    public Result login(@RequestBody Admin admin){
        return adminService.login(admin);
    }

    @ApiOperation("浏览管理员列表接口")
    @GetMapping("/adminManage")
    public Result queryAdminList(){
        return adminService.queryAdminList();
    }

    @ApiOperation("添加管理员接口")
    @PostMapping("/adminManage")
    public Result addAdmin(@RequestBody Admin admin){
        return adminService.addAdmin(admin);
    }

    @ApiOperation("更新管理员接口")
    @PutMapping("/adminManage")
    public Result updateAdmin(@RequestBody Admin admin){
        return adminService.updateAdmin(admin);
    }

    @ApiOperation("删除管理员接口")
    @DeleteMapping("/adminManage/{adminId}")
    public Result delAdmin(@PathVariable long adminId){
        System.out.println("recieve delete admin");
        return adminService.delAdmin(adminId);
    }
}
